package com.attendance.common;

import lombok.Data;

@Data
public class CommonResult<T> {
    private long code;
    private String message;
    private boolean flag;
    private T data;

    protected CommonResult() {
    }

    protected CommonResult(long code, boolean flag, String message, T data) {
        this.code = code;
        this.flag = flag;
        this.message = message;
        this.data = data;
    }

    public CommonResult(long code, boolean flag, String message) {
        this.code = code;
        this.flag = flag;
        this.message = message;
    }

    public static <T> CommonResult<T> success(T data) {
        return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getFlag(), ResultCode.SUCCESS.getMessage(), data);
    }

    public static <T> CommonResult<T> success(T data, String message) {
        return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getFlag(), message, data);
    }

    public static <T> CommonResult<T> success(String message) {
        return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getFlag(), message);
    }

    public static <T> CommonResult<T> failed(IErrorCode errorCode) {
        return new CommonResult(errorCode.getCode(), errorCode.getFlag(), errorCode.getMessage(), (Object)null);
    }

    public static <T> CommonResult<T> failed(IErrorCode errorCode, String message) {
        return new CommonResult(errorCode.getCode(), errorCode.getFlag(), message, (Object)null);
    }

    public static <T> CommonResult<T> failed(String message) {
        return new CommonResult(ResultCode.FAILED.getCode(), ResultCode.FAILED.getFlag(), message, (Object)null);
    }

    public static <T> CommonResult<T> failed() {
        return failed((IErrorCode)ResultCode.FAILED);
    }

    public static <T> CommonResult<T> validateFailed() {
        return failed((IErrorCode)ResultCode.VALIDATE_FAILED);
    }

    public static <T> CommonResult<T> validateFailed(String message) {
        return new CommonResult(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getFlag(), message, (Object)null);
    }

    public static <T> CommonResult<T> unauthorized(T data) {
        return new CommonResult(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getFlag(), ResultCode.UNAUTHORIZED.getMessage(), data);
    }

    public static <T> CommonResult<T> forbidden(T data) {
        return new CommonResult(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getFlag(), ResultCode.FORBIDDEN.getMessage(), data);
    }
}
